package com.ruoyi.hr.service.impl;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.hr.domain.Departments;
import com.ruoyi.hr.domain.Tree;
import com.ruoyi.hr.mapper.CompanysMapper;
import com.ruoyi.hr.mapper.DepartmentsMapper;
import com.ruoyi.hr.mapper.OrgnMapper;
import com.ruoyi.hr.service.CompanysService;
import com.ruoyi.hr.service.DepartmentsService;
import com.ruoyi.hr.util.TreeBulid;
import org.apache.ibatis.annotations.Param;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentsServiceImpl implements DepartmentsService {


    @Autowired
    private DepartmentsMapper departmentsMapper;

    @Autowired
    private OrgnMapper orgnMapper;


    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<String> findSubdepartmentID(List<String> AllID) {
        return departmentsMapper.findSubdepartmentID(AllID);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Departments> findDep(Long compID) {
        return departmentsMapper.findDep(compID);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public int findCount(Departments departments,List<String> AllID) {
        return departmentsMapper.findCount(departments,AllID);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Departments> findAll(int PageNum,int PageSize,Departments departments,List<String> AllID) {
        return departmentsMapper.findAll((PageNum - 1) * PageSize,PageSize,departments,AllID);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public Departments findDepOne(Long depID) {
        return departmentsMapper.findDepOne(depID);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Departments> findAllDepart() {
        return departmentsMapper.findAllDepart();
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public int updateDepartments(Departments departments) {
        return departmentsMapper.updateDepartments(departments);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public int insertDepartments(Departments departments) {
        return departmentsMapper.insertDepartments(departments);
    }


    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public Tree<T> findAllTree(List<String> AllID, String CompID, String type) {
        return TreeBulid.build(orgnMapper.findAllTree(AllID, CompID, type));
    }


    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public Departments findadminDep(Long depID) {
        return departmentsMapper.findadminDep(depID);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<String> getDepRow() {
        return departmentsMapper.getDepRow();
    }
}
